package com.njym.java.security.app.rest;

import com.njym.java.security.app.biz.InvestTimeBiz;
import com.njym.java.security.app.biz.InvestUserBiz;
import com.njym.java.security.app.entity.InvestTime;
import com.njym.java.security.app.entity.InvestUser;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("investUser")
public class InvestUserController extends BaseController<InvestUserBiz,InvestUser> {

    @Autowired
    private InvestTimeBiz investTimeBiz;

    /**
     * 用户问卷登陆
     * @param name
     * @param mobile
     * @param appUserId
     * @param groupName
     * @param investCode
     * @param typetblId
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    @ResponseBody
    public Object add(
            String name,String mobile,Integer appUserId,String groupName,
            String investCode,Integer typetblId

    ){
        List<InvestUser> investUsers = baseBiz.queryByParam(name,mobile,investCode,typetblId);
        // 判断问卷用户是否重复登陆
        if(investUsers.size() == 0){
            InvestUser investUser = new InvestUser();
            investUser.setName(name);
            investUser.setMobile(mobile);
            investUser.setGroupName(groupName);
            investUser.setAppUserId(appUserId);
            InvestTime investTime = investTimeBiz.queryList(investCode,typetblId);
            // 判断用户输入的问卷编号是否存在
            if(investTime != null){
                investUser.setInvestTimeId(investTime.getId());
                baseBiz.insertSelective(investUser);
                return new ObjectRestResponse<Object>().rel(true).data(1);
            }else {
                return new ObjectRestResponse<Object>().rel(true).data(2);
            }
        }else {
            return new ObjectRestResponse<Object>().rel(true).data(3);
        }


    }

}